home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / mexico86.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  3KB  |  130 lines

  1. #include "driver.h"
  2.  
  3.  
  4. unsigned char *mexico86_protection_ram;
  5.  
  6.  
  7. /***************************************************************************
  8.  
  9.  Mexico 86 68705 protection interface
  10.  
  11.  The following is ENTIRELY GUESSWORK!!!
  12.  
  13. ***************************************************************************/
  14.  
  15. int mexico86_m68705_interrupt(void)
  16. {
  17.     /* I don't know how to handle the interrupt line so I just toggle it every time. */
  18.     if (cpu_getiloops() & 1)
  19.         cpu_set_irq_line(2,0,CLEAR_LINE);
  20.     else
  21.         cpu_set_irq_line(2,0,ASSERT_LINE);
  22.  
  23.     return 0;
  24. }
  25.  
  26.  
  27.  
  28. static unsigned char portA_in,portA_out,ddrA;
  29.  
  30. READ_HANDLER( mexico86_68705_portA_r )
  31. {
  32. //logerror("%04x: 68705 port A read %02x\n",cpu_get_pc(),portA_in);
  33.     return (portA_out & ddrA) | (portA_in & ~ddrA);
  34. }
  35.  
  36. WRITE_HANDLER( mexico86_68705_portA_w )
  37. {
  38. //logerror("%04x: 68705 port A write %02x\n",cpu_get_pc(),data);
  39.     portA_out = data;
  40. }
  41.  
  42. WRITE_HANDLER( mexico86_68705_ddrA_w )
  43. {
  44.     ddrA = data;
  45. }
  46.  
  47.  
  48.  
  49. /*
  50.  *  Port B connections:
  51.  *
  52.  *  all bits are logical 1 when read (+5V pullup)
  53.  *
  54.  *  0   W  enables latch which holds data from main Z80 memory
  55.  *  1   W  loads the latch which holds the low 8 bits of the address of
  56.  *               the main Z80 memory location to access
  57.  *  2   W  0 = read input ports, 1 = access Z80 memory
  58.  *  3   W  clocks main Z80 memory access
  59.  *  4   W  selects Z80 memory access direction (0 = write 1 = read)
  60.  *  5   W  clocks a flip-flop which causes IRQ on the main Z80
  61.  *  6   W  not used?
  62.  *  7   W  not used?
  63.  */
  64.  
  65. static unsigned char portB_in,portB_out,ddrB;
  66.  
  67. READ_HANDLER( mexico86_68705_portB_r )
  68. {
  69.     return (portB_out & ddrB) | (portB_in & ~ddrB);
  70. }
  71.  
  72. static int address,latch;
  73.  
  74. WRITE_HANDLER( mexico86_68705_portB_w )
  75. {
  76. //logerror("%04x: 68705 port B write %02x\n",cpu_get_pc(),data);
  77.  
  78.     if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
  79.     {
  80.         portA_in = latch;
  81.     }
  82.     if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02)) /* positive edge trigger */
  83.     {
  84.         address = portA_out;
  85. //if (address >= 0x80) logerror("%04x: 68705 address %02x\n",cpu_get_pc(),portA_out);
  86.     }
  87.     if ((ddrB & 0x08) && (~data & 0x08) && (portB_out & 0x08))
  88.     {
  89.         if (data & 0x10)    /* read */
  90.         {
  91.             if (data & 0x04)
  92.             {
  93. //logerror("%04x: 68705 read %02x from address %04x\n",cpu_get_pc(),shared[0x800+address],address);
  94.                 latch = mexico86_protection_ram[address];
  95.             }
  96.             else
  97.             {
  98. //logerror("%04x: 68705 read input port %04x\n",cpu_get_pc(),address);
  99.                 latch = readinputport((address & 1) + 1);
  100.             }
  101.         }
  102.         else    /* write */
  103.         {
  104. //logerror("%04x: 68705 write %02x to address %04x\n",cpu_get_pc(),portA_out,address);
  105.                 mexico86_protection_ram[address] = portA_out;
  106.         }
  107.     }
  108.     if ((ddrB & 0x20) && (data & 0x20) && (~portB_out & 0x20))
  109.     {
  110.         cpu_irq_line_vector_w(0,0,mexico86_protection_ram[0]);
  111. //        cpu_set_irq_line(0,0,HOLD_LINE);
  112.         cpu_set_irq_line(0,0,PULSE_LINE);
  113.     }
  114.     if ((ddrB & 0x40) && (~data & 0x40) && (portB_out & 0x40))
  115.     {
  116. logerror("%04x: 68705 unknown port B bit %02x\n",cpu_get_pc(),data);
  117.     }
  118.     if ((ddrB & 0x80) && (~data & 0x80) && (portB_out & 0x80))
  119.     {
  120. logerror("%04x: 68705 unknown port B bit %02x\n",cpu_get_pc(),data);
  121.     }
  122.  
  123.     portB_out = data;
  124. }
  125.  
  126. WRITE_HANDLER( mexico86_68705_ddrB_w )
  127. {
  128.     ddrB = data;
  129. }
  130.